/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import fever.conf.ConfigurationUI;
import fever.display.text.AntiAliasType;
import fever.Fever;

import flash.filters.DropShadowFilter;

/**
 * Display configuration progression.
 * 
 * <p>You can extends this class to deploy a better visual.
 * 
 * @see fever.conf.Configuration
 * 
 * @author Romain Ecarnot
 */
class fever.conf.BasicConfigurationUI implements ConfigurationUI
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _mc : MovieClip;
	private var _tx : TextField;
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function BasicConfigurationUI()
	{
		_configureUI();
	}	
	
	/**
	 * Triggered when configuration state change.
	 */
	public function setState( s : String ) : Void
	{
		Fever.application.setTitle( null, s );
		_tx.text = s;
	}
	
	/**
	 * Triggered when configuration is loaded and parsed.
	 */
	public function release() : Void
	{
		Stage.removeListener( this );
		_mc.removeMovieClip();
		Fever.application.setTitle( null, "" );
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Builds a simple UI for loading listening.
	 */
	private function _configureUI() : Void
	{
		_mc = Fever.stage.createOverlayTarget( "_configLoader_" );
		
		var back : MovieClip = _mc.createEmptyMovieClip( "__back__", 3 );
		back.lineStyle( 2, 0x6F7777, 100, true, "none", "round", "round" );
		back.beginFill( 0xffffff, 100 );
		_drawRect( back, 200, 20 );
		back.endFill();
		
		_tx = _mc.createTextField( "__l__", 6, 0, 2, 200, 20 );
		_tx.antiAliasType = AntiAliasType.ADVANCED;
		_tx.selectable = false;
		
		var tf : TextFormat = new TextFormat( "_sans", 10, 0x333333 );
		tf.align = "center";
		_tx.setNewTextFormat( tf );
		
		var filter : DropShadowFilter = new DropShadowFilter( 1, 0, 0x000000, 15, 15, 15, 0.25 );
		_mc.filters = new Array( filter );
		
		Stage.addListener( this );
		onResize();
	}
	
	/**
	 * Simple drawing method.
	 */
	private function _drawRect( target : MovieClip, w : Number, h : Number ) : Void
	{
		target.moveTo( 0, 0 );
		target.lineTo( w, 0 );
		target.lineTo( w, h );
		target.lineTo( 0, h );
		target.lineTo( 0, 0 );	
	}
	
	/**
	 * Triggered by the Stage.
	 */
	private function onResize() : Void
	{
		_mc._x = Stage.width /2 - _mc._width /2;
		_mc._y = Stage.height /2 - _mc._height /2;
	}
}